#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

ll read(){
	ll x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}
const int mod = 1e9+7;

map<ll,ll> f;

ll dp(ll x){
	if(f[x]) return f[x];
	if(x == 0) return 1;
	else if(x == 1) return 2;
	if(x & 1) return f[x] = (2 * dp(x >> 1) + dp((x >> 1) - 1)) % mod;
	else return f[x] = (2 * dp((x >> 1) - 1) + dp(x >> 1)) % mod;
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	ll n = in;
	printf("%lld\n",dp(n));
	return 0;
}

